package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;
import static com.example.fw.ContactHelper.MODIFICATION;

import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

public class ContactModificationTests extends TestBase {
	 @Test
	  public void ContactModification() throws Exception {

	 	// save old state
		 SortedListOf<ContactData> oldList = app.getContactHelper().getDbContacts();
	    
	    Random rnd = new Random();
	    int index = rnd.nextInt(oldList.size());
		
		//action
	    ContactData contact = new ContactData()
	    	.withFirstname("new first name")
	    	.withLastname("new last name")
	    	.withAddress("new Address")
	    	.withHome_tel("new Home_tel")
	    	.withMobile_tel("new Mobile_tel")
	    	.withWork_tel("new Work_tel")
	    	.withEmail_1("new Email_1")
	    	.withEmail_2("new Email_2")
	    	.withBday("15")
	    	.withBmonth("May")
	    	.withByear("1900")
	    	.withAddress2("new Address2")
	    	.withPhone2("new Phone2");
	    app.getContactHelper().modifyContact(index, contact, MODIFICATION);

	    
	    //save new state
	    SortedListOf<ContactData> newList = app.getContactHelper().getUiFullContacts();
	    
	    //compare states
	    assertThat(newList, equalTo(oldList.without(index).withAdded(contact)));
	 }
}
